package cn.iocoder.yudao.module.pay.controller.app.packagec;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.pay.controller.admin.packagec.vo.PackagePageReqVO;
import cn.iocoder.yudao.module.pay.controller.admin.packagec.vo.PackageRespVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.packagec.PackageDO;
import cn.iocoder.yudao.module.pay.service.packagec.PackageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "APP（有关笔试） - 套餐")
@RestController
@RequestMapping("/pay/package")
@Validated
public class AppPackageController {

    @Resource
    private PackageService packageService;

    @GetMapping("/page")
    @Operation(summary = "获得套餐分页")
    public CommonResult<PageResult<PackageRespVO>> getPackagePage(@Valid PackagePageReqVO pageReqVO) {
        PageResult<PackageDO> pageResult = packageService.getPackagePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PackageRespVO.class));
    }

    @GetMapping("/get")
    @Operation(summary = "获得套餐")
    public CommonResult<PackageRespVO> getPackage(@RequestParam("id") Long id) {
        PackageDO packageDO = packageService.getPackage(id);
        return success(BeanUtils.toBean(packageDO, PackageRespVO.class));
    }

}